﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Resources;
using System.Globalization;

using TrainingCenterSystem;
using TrainingCenterSystem.TestManagement;


namespace TrainingCenterWinClient.Forms
{
    public partial class TestResultForm : Form
    {
        #region private members
        private TrainingCenter _trainingCenter;
        private ResourceManager _resMgr;       
        private IndividualTest _individualTest;
        #endregion

        #region constructors
        public TestResultForm(TrainingCenter trainingCenter, IndividualTest indivTest)
        {
            InitializeComponent();
            _trainingCenter = trainingCenter;
            _individualTest = indivTest;

            this.initForm();

            this.showResults();
        }
        #endregion

        #region methods

        /// <summary>
        /// Initializes the form
        /// </summary>
        private void initForm()
        {
            // init language
            this.UpdateLanguage(_trainingCenter.CurrentLanguageID);           
        }

        /// <summary>
        /// Updates the language of the UI
        /// </summary>
        /// <param name="langID">the language-id</param>
        private void UpdateLanguage(string langID)
        {
            try
            {
                // Set Language
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(langID);

                // Init ResourceManager
                _resMgr =
                        new ResourceManager("TrainingCenterWinClient.ReStrings",
                        typeof(TestExecutionForm).Assembly);

                // assign localized strings to UI                
                this.Text = _resMgr.GetString("TestResultForm_caption");
                this.lblTotalQuestionText.Text = _resMgr.GetString("TestResultForm_lblTotalQuestionText");
                this.lblCorrectQuestionText.Text=_resMgr.GetString("TestResultForm_lblCorrectQuestionText");
                this.lblPartialQuestionText.Text = _resMgr.GetString("TestResultForm_lblPartialQuestionText");
                this.lblIncorrectQuestionText.Text = _resMgr.GetString("TestResultForm_lblIncorrectQuestionText");                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void showResults()
        {
            int correct = 0;
            int partial = 0;
            int incorrect = 0;

            for (int i = 0; i < _individualTest.TestAnswers.Count; i++)
            {
                if (_individualTest.TestAnswers[i].AnswerStatus == AnswerStatus.Correct)
                    correct++;
                else if (_individualTest.TestAnswers[i].AnswerStatus == AnswerStatus.Partial)
                    partial++;
                else if (_individualTest.TestAnswers[i].AnswerStatus == AnswerStatus.Incorrect)
                    incorrect++;
            }

            this.lblTotalQuestions.Text = _individualTest.TestQuestions.Count.ToString();
            this.lblCorrectQuestions.Text = correct.ToString();
            this.lblPartialQuestions.Text = partial.ToString();
            this.lblIncorrectQuestions.Text = incorrect.ToString();
        }
        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }
        #endregion
    }
}
